﻿<phone:PhoneApplicationPage x:Class="Strava1.RideDetails"
                            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                            xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
                            xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
                            xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
                            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                            xmlns:tk="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
                            xmlns:map="clr-namespace:Microsoft.Phone.Controls.Maps;assembly=Microsoft.Phone.Controls.Maps"
                            xmlns:mapCore="clr-namespace:Microsoft.Phone.Controls.Maps.Core;assembly=Microsoft.Phone.Controls.Maps"
                            xmlns:local="clr-namespace:Strava1"
                            mc:Ignorable="d"
                            d:DesignWidth="480"
                            d:DesignHeight="768"
                            FontFamily="{StaticResource PhoneFontFamilyNormal}"
                            FontSize="{StaticResource PhoneFontSizeNormal}"
                            Foreground="{StaticResource PhoneForegroundBrush}"
                            SupportedOrientations="Portrait"
                            Orientation="Portrait"
                            shell:SystemTray.IsVisible="True">
    <shell:SystemTray.ProgressIndicator>
        <shell:ProgressIndicator IsIndeterminate="{Binding Busy}"
                                 IsVisible="{Binding Busy}"
                                 Text="{Binding BusyMessage}" />
    </shell:SystemTray.ProgressIndicator>

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot"
          Background="Transparent">
        <!--Pivot Control-->
        <controls:Pivot x:Name="myPivot"
                        Title="{Binding Name, StringFormat='STRAVA VIEWER - {0}'}">
            <controls:Pivot.Background>
                <ImageBrush ImageSource="SplashScreenImage2.png"
                            Opacity="0.75" />
            </controls:Pivot.Background>
            <!--Pivot item one-->
            <controls:PivotItem Header="details">
                <Grid Margin="12,0,0,10">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="{Binding Name}"
                               TextWrapping="Wrap"
                               Grid.ColumnSpan="2"
                               FontSize="{StaticResource PhoneFontSizeMedium}" />

                    <Grid Grid.Row="1"
                          Grid.ColumnSpan="2">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="overall: "
                                       FontSize="{StaticResource PhoneFontSizeMedium}" />
                            <TextBlock Text="{Binding OverallFirstPositionCount, StringFormat='{}{0}, '}"
                                       FontSize="{StaticResource PhoneFontSizeMedium}" />
                            <TextBlock Text="{Binding OverallSecondPositionCount, StringFormat='{}{0}, '}"
                                       FontSize="{StaticResource PhoneFontSizeMedium}" />
                            <TextBlock Text="{Binding OverallThirdPositionCount, StringFormat='{}{0}, '}"
                                       FontSize="{StaticResource PhoneFontSizeMedium}" />
                            <TextBlock Text="{Binding OverallOtherPositionCount}"
                                       FontSize="{StaticResource PhoneFontSizeMedium}" />
                        </StackPanel>

                        <StackPanel Orientation="Horizontal"
                                    HorizontalAlignment="right"
                                    Grid.Column="1">
                            <TextBlock Text="my results: "
                                       FontSize="{StaticResource PhoneFontSizeMedium}" />
                            <TextBlock Text="{Binding MyFirstPositionCount, StringFormat='{}{0}, '}"
                                       FontSize="{StaticResource PhoneFontSizeMedium}" />
                            <TextBlock Text="{Binding MySecondPositionCount, StringFormat='{}{0}, '}"
                                       FontSize="{StaticResource PhoneFontSizeMedium}" />
                            <TextBlock Text="{Binding MyThirdPositionCount, StringFormat='{}{0}, '}"
                                       FontSize="{StaticResource PhoneFontSizeMedium}" />
                            <TextBlock Text="{Binding MyOtherPositionCount}"
                                       FontSize="{StaticResource PhoneFontSizeMedium}" />
                        </StackPanel>
                    </Grid>

                    <TextBlock Text="{Binding Detail.StartDate, StringFormat='{}{0:D}'}"
                               Grid.Row="3"
                               Foreground="{StaticResource PhoneSubtleBrush}" />
                    <TextBlock Text="{Binding Detail.Distance, Converter={StaticResource MeterToKMConverter}, StringFormat='{}{0:n1}km'}"
                               Grid.Row="3"
                               Grid.Column="1"
                               Foreground="{StaticResource PhoneSubtleBrush}" />
                    <Grid Grid.Row="4"
                          Grid.ColumnSpan="2">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                            <ColumnDefinition />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>

                        <TextBlock Text="{Binding Detail.AverageSpeed, Converter={StaticResource MPSToMPHConverter}, StringFormat='{}{0:n1}mph'}"
                                   Foreground="{StaticResource PhoneSubtleBrush}" />
                        <TextBlock Text="{Binding Detail.ElevationGain, Converter={StaticResource MeterToFeetConverter}, StringFormat='{}{0:n0}ft'}"
                                   Grid.Column="1"
                                   HorizontalAlignment="Center"
                                   Foreground="{StaticResource PhoneSubtleBrush}" />
                        <TextBlock Text="{Binding Detail.Bike.Name}"
                                   Grid.Column="2"
                                   HorizontalAlignment="Right"
                                   Foreground="{StaticResource PhoneSubtleBrush}" />
                    </Grid>
                    <map:Map Grid.Row="5"
                             Margin="0,10"
                             ZoomLevel="{Binding ZoomLevel}"
                             x:Name="myMap"
                             Center="{Binding MapCenter}"
                             Grid.ColumnSpan="3"
                             CredentialsProvider="AoOAVXaPhN9YePJC_ptD_S4M42CEVLKGJ4lxiIksAOBaPdJtE6havx99boLZn9G8"
                             CopyrightVisibility="Collapsed"
                             LogoVisibility="Collapsed">
                        <map:Map.Mode>
                            <mapCore:MercatorMode />
                        </map:Map.Mode>
                        <map:Map.Children>
                            <map:MapTileLayer>
                                <map:MapTileLayer.TileSources>
                                    <local:OpenCycleMap />
                                </map:MapTileLayer.TileSources>
                            </map:MapTileLayer>
                            <map:MapItemsControl ItemsSource="{Binding MapObjects}">
                                <map:MapItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <map:MapPolyline Loaded="MapPolyline_Loaded"
                                                         Locations="{Binding Locations}" />
                                    </DataTemplate>
                                </map:MapItemsControl.ItemTemplate>
                            </map:MapItemsControl>
                        </map:Map.Children>

                    </map:Map>

                    <ItemsControl ItemsSource="{Binding ProfilePathObjects}"
                                  Grid.Row="6"
                                  Height="100">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <Canvas />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Path Stroke="{Binding Stroke}"
                                      StrokeThickness="{Binding StrokeThickness}"
                                      Fill="{Binding Fill}"
                                      Data="{Binding PathGeometry}" />
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>

                    <!--<Slider x:Name="slider"
                            Style="{StaticResource ProfileSliderStyle}"
                            Grid.Row="6"
                            Orientation="Horizontal"
                            Minimum="0"
                            Maximum="100" />-->
                </Grid>
            </controls:PivotItem>

            <controls:PivotItem Header="{Binding Efforts.Count, StringFormat='{}{0} segments'}">
                <!--Double line list with image placeholder and text wrapping-->
                <ListBox x:Name="effortsLB"
                         tk:TiltEffect.IsTiltEnabled="True"
                         DataContext="{Binding EffortsCVS}"
                         ItemsSource="{Binding}">
                    <!--<tk:ContextMenuService.ContextMenu>
                        <tk:ContextMenu>
                            <tk:MenuItem Header="placing"
                                         Click="SetSegmentOrder_Click" />
                            <tk:MenuItem Header="distance"
                                         Click="SetSegmentOrder_Click" />
                            <tk:MenuItem Header="elevation"
                                         Click="SetSegmentOrder_Click" />
                            <tk:MenuItem Header="gradient"
                                         Click="SetSegmentOrder_Click" />
                            <tk:MenuItem Header="rating"
                                         Click="SetSegmentOrder_Click" />
                            <tk:MenuItem Header="name"
                                         Click="SetSegmentOrder_Click" />
                        </tk:ContextMenu>
                    </tk:ContextMenuService.ContextMenu>-->
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Grid Margin="12,0,0,10">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <StackPanel Width="100">
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="{Binding Segment.TopPlacing, StringFormat='{}{0}/', Converter={StaticResource CountMaxConverter}}"
                                                   Margin="12,-6,0,0"
                                                   FontSize="{StaticResource PhoneFontSizeLarge}" />
                                        <TextBlock Text="{Binding Segment.PlacingCount, Converter={StaticResource textConv}}"
                                                   Margin="0,-6,12,0"
                                                   FontSize="{StaticResource PhoneFontSizeLarge}" />
                                    </StackPanel>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="{Binding MyPlacing, StringFormat='{}{0}/', Converter={StaticResource CountMaxConverter}}"
                                                   Margin="12,-6,0,0"
                                                   Foreground="{StaticResource PhoneSubtleBrush}"
                                                   FontSize="{StaticResource PhoneFontSizeLarge}" />
                                        <TextBlock Text="{Binding Segment.MyEffortsCount, Converter={StaticResource textConv}}"
                                                   Margin="0,-6,12,0"
                                                   Foreground="{StaticResource PhoneSubtleBrush}"
                                                   FontSize="{StaticResource PhoneFontSizeLarge}" />
                                    </StackPanel>
                                </StackPanel>
                                <StackPanel Grid.Column="1">
                                    <TextBlock Text="{Binding Segment.Name}"
                                               TextWrapping="Wrap"
                                               FontSize="{StaticResource PhoneFontSizeMedium}" />
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition />
                                            <ColumnDefinition />
                                            <ColumnDefinition />
                                        </Grid.ColumnDefinitions>

                                        <TextBlock Text="{Binding Segment.Distance, Converter={StaticResource MeterToKMConverter}, StringFormat='{}{0:n2}km'}"
                                                   Foreground="{StaticResource PhoneSubtleBrush}" />
                                        <TextBlock Text="{Binding Segment.ElevationDifference, Converter={StaticResource MeterToFeetConverter}, StringFormat='{}{0:n0}ft'}"
                                                   Grid.Column="1"
                                                   HorizontalAlignment="Center"
                                                   Foreground="{StaticResource PhoneSubtleBrush}" />
                                        <TextBlock Text="{Binding Segment.AverageGrade, StringFormat='{}{0:n1}%'}"
                                                   Grid.Column="2"
                                                   HorizontalAlignment="Right"
                                                   Foreground="{StaticResource PhoneSubtleBrush}" />
                                    </Grid>
                                </StackPanel>
                                <TextBlock Text="{Binding Segment.ClimbCategory, Converter={StaticResource JustIntConverter}}"
                                           Width="40"
                                           TextAlignment="Right"
                                           Grid.Column="2"
                                           FontSize="{StaticResource PhoneFontSizeLarge}" />
                            </Grid>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </controls:PivotItem>
        </controls:Pivot>
    </Grid>

    <!--Sample code showing usage of ApplicationBar-->
    <!--<phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
            <shell:ApplicationBarIconButton x:Name="appbar_button1" IconUri="/Images/appbar_button1.png" Text="Button 1"/>
            <shell:ApplicationBarIconButton x:Name="appbar_button2" IconUri="/Images/appbar_button2.png" Text="Button 2"/>
            <shell:ApplicationBar.MenuItems>
                <shell:ApplicationBarMenuItem x:Name="menuItem1" Text="MenuItem 1"/>
                <shell:ApplicationBarMenuItem x:Name="menuItem2" Text="MenuItem 2"/>
            </shell:ApplicationBar.MenuItems>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>-->

</phone:PhoneApplicationPage>